#include <myheader.h>

/*Usage: lseek函数，获取文件大小*/
int main(int argc, char *argv[])
{
    ARGC_CHECK(argc,2);
    //只读形式打开
    int fd = open(argv[1],O_RDONLY);
    ERROR_CHECK(fd,-1,"file_open");
    //获取文件大小
    ssize_t file_size = lseek(fd, 0, SEEK_END);
    ERROR_CHECK(file_size,-1,"lseek_file_size");
    printf("file_size = %lu\n",file_size);
    //读取文件需要重新将文件指针移到文件开头
    ssize_t lseek_ret = lseek(fd,0,SEEK_SET);
    ERROR_CHECK(lseek_ret,-1,"lseek_set");
    char buf[1024];
    ssize_t read_count;
    while((read_count = read(fd,buf,sizeof(buf))) > 0){
        printf("read_count = %lu\n",read_count);
        printf("%s\n",buf);
        memset(buf,0,sizeof(buf));
          }
    int close_ret = close(fd);
    ERROR_CHECK(close_ret,-1,"closefile");
    return 0;
}

